<template>
  <view class="bg-default">
    <!--        <socialuni-user-detail-view></socialuni-user-detail-view>-->
    <socialuni-community-user-detail-view>
      <template #navBarRight>
        <div class="row-end-center flex-1">
          <q-icon icon="list-dot" size="20" @click="openMoreMenu"></q-icon>
        </div>
      </template>
      <template #userBaseInfoRightPre>
        <q-button @click="toMessagePage" class="mr-sm">
          <q-icon icon="mdi-chat-outline" size="14"></q-icon>
          私信
        </q-button>
      </template>
    </socialuni-community-user-detail-view>

    <q-popup ref="moreActionMenu" bottom>
      <uni-list class="pb-xl">
        <uni-list-item title="解除好友" link
                       @click="deleteFriend"></uni-list-item>
        <uni-list-item title="加入黑名单" link
                       @click="addBlack"></uni-list-item>
        <uni-list-item title="从黑名单移除" link
                       @click="removeBlack"></uni-list-item>
      </uni-list>
    </q-popup>
  </view>
</template>

<script lang="ts">
import SocialuniCommunityUserDetailView
  from "@socialuni/socialuni-community-view-uni/src/views/user/SocialuniCommunityUserDetailView.vue";
import QButton from "@socialuni/socialuni-ui-uni/src/components/QButton/QButton.vue";
import QIcon from "@socialuni/socialuni-ui-uni/src/components/QIcon/QIcon.vue";
import QPopup from "@socialuni/socialuni-ui-uni/src/components/QPopup/QPopup.vue";
import {Component, Vue} from "vue-facing-decorator";
import SocialuniAppUtil from "@socialuni/socialuni-native-util/src/util/SocialuniAppUtil";
import SocialuniUserDetailView from "@socialuni/socialuni-user-view-uni/src/views/user/SocialuniUserDetailView.vue";
import {socialuniChatModule} from "@socialuni/socialuni-im-sdk/src/store/SocialuniChatModule";
import {socialuniUserDetailViewService} from "@socialuni/socialuni-user-sdk/src/logic/SocialuniUserDetailViewService";

@Component({
  components: {
    QPopup,
    QButton,
    QIcon,
    SocialuniUserDetailView,
    SocialuniCommunityUserDetailView
  }
})
export default class UserDetailPage extends Vue {
  $refs: {
    moreActionMenu: QPopup
  }

  openMoreMenu() {
    this.$refs.moreActionMenu.open()
  }


  /**
   * 从好友列表中删除用户。
   */
  async deleteFriend() {
    SocialuniAppUtil.AlertUtil.confirm('是否确认解除好友关系').then(async () => {
      /*(await socialChatModule.openIm()).deleteFriend(socialuniUserDetailViewService.user.id).then(({data}) => {
          console.log('deleteFriend', data)
          SocialuniAppUtil.ToastUtil.toast('成功解除好友关系')
          socialChatModule.checkFriend(socialuniUserDetailViewService.user)
      }).catch(err => {
      })*/
    })
  }


  /**
   * 将用户添加到黑名单。
   */
  async addBlack() {
    /* SocialuniAppUtil.AlertUtil.confirm('是否确认添加到黑名单').then(async () => {
         (await socialChatModule.openIm()).addBlack(this.user.id).then(({data}) => {
             socialChatModule.checkFriend(this.user)
         }).catch(err => {
         })
     })*/

  }


  /**
   * 将用户从黑名单移除。
   */
  async removeBlack() {
    /*SocialuniAppUtil.AlertUtil.confirm('是否确认从黑名单移除').then(async () => {
        (await socialChatModule.openIm()).removeBlack(this.user.id).then(({data}) => {
            socialChatModule.checkFriend(this.user)
        }).catch(err => {
        })
    })*/
  }

  async toMessagePage() {
    socialuniChatModule.setChatIdToMessagePage(socialuniUserDetailViewService.user.id)
  }

}
</script>
